import http from '@/api/http.js'
import weixinPay from '@/utils/pay.weixin.js'

/**
 * @param {Number} orderData 订单信息
 * @description 检查微信小程序的支付方式
  */
const checkPayWay = async function(orderData, successFun, failFun){
	// 获取支付列表
	let params = {
			method: 'api/v2/payment/index/index',
			ordersn: orderData.ordersn,
			comefrom: 'wxxcx',
			is_wx_client: 0
		}
	let res = await http(params)
	if (res.status) {
		//是否安装会员充值应用与工行支付，typeid196为钱包充值订单
		let newPage = 0;//默认不跳转
		if(orderData.typeid != '196'){
			let onLine = res.data.pay_method.online;
			onLine.map(item => {
				// 如果有'wallet'或'icbcpay',则跳转到支付方式页面
				if(item.pinyin == 'wallet' || item.pinyin == 'icbcpay'){
					newPage++;
				}
			})
		}
		if(!newPage){
			weixinPay(orderData,successFun,failFun)
		}else{
			// 前往支付页面
			if(orderData.pageType == 1){ // 为关闭当前页面跳转
				uni.redirectTo({
					url: `/platforms/mp-weixin/pay/index?ordersn=${orderData.ordersn}`
				})
			}else{ // 直接跳转
				uni.navigateTo({
					url: `/platforms/mp-weixin/pay/index?ordersn=${orderData.ordersn}`
				})	
			}
			
		}
			
	}
}
export default checkPayWay
